package com.lihui.removeelement;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/09/28  16:34
 */
public class RemoveNum {
    public static void main(String[] args) {
        int[] nums = {3,2,2,3};
        Solution solution = new Solution();
        System.out.println(solution.removeElement(nums, 2));
    }
}
class Solution {
    public int removeElement(int[] nums, int val) {
        if(nums == null || nums.length == 0){
            return 0;
        }
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val){
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
        }
    }

